package com.xw.unification.interceptor;

import com.xw.unification.enums.UnifiedRequestInterceptorStep;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author qiwei
 */
@Getter
@Setter
public class UnifiedRequestInterceptorChainContext {
    private int total;
    private int nowIndex;
    private List<UnifiedRequestInterceptorChainNodeContext> errorNodeList = new ArrayList<>();

    public UnifiedRequestInterceptorChainContext init(int total) {
        this.total = Math.max(total, 0);
        this.nowIndex = total > 0 ? 0 : -1;
        errorNodeList.clear();
        return this;
    }

    public void addErrorNode(int index, UnifiedRequestInterceptor interceptor,
                             UnifiedRequestInterceptorStep step, Exception e) {
        errorNodeList.add(new UnifiedRequestInterceptorChainNodeContext(index, interceptor, step, e));
    }
}
